package com.ruoyi.web.controller.plan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.plan.domain.NoticePlan;
import com.ruoyi.plan.service.INoticePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author MLYNDHG
 * @version 1.0
 * @description 计划通知Controller
 * @date 2023/12/18 14:47
 */
@RestController
@RequestMapping("/plan/notice")
public class NoticePlanController extends BaseController
{
 @Autowired
 private INoticePlanService noticePlanService;

 /**
  * 查询计划通知列表
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:list')")
 @GetMapping("/list")
 public TableDataInfo list(NoticePlan noticePlan)
 {
  startPage();
  List<NoticePlan> list = noticePlanService.selectNoticePlanList(noticePlan);
  return getDataTable(list);
 }

 /**
  * 导出计划通知列表
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:export')")
 @Log(title = "计划通知", businessType = BusinessType.EXPORT)
 @PostMapping("/export")
 public void export(HttpServletResponse response, NoticePlan noticePlan)
 {
  List<NoticePlan> list = noticePlanService.selectNoticePlanList(noticePlan);
  ExcelUtil<NoticePlan> util = new ExcelUtil<NoticePlan>(NoticePlan.class);
  util.exportExcel(response, list, "计划通知数据");
 }

 /**
  * 随机查询计划通知
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:query')")
 @GetMapping("/listRandom")
 public AjaxResult getInfoRandom()
 {
  return success(noticePlanService.selectNoticePlanRandom());
 }

 /**
  * 获取计划通知详细信息
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:query')")
 @GetMapping(value = "/{id}")
 public AjaxResult getInfo(@PathVariable("id") Long id)
 {
  return success(noticePlanService.selectNoticePlanById(id));
 }

 /**
  * 新增计划通知
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:add')")
 @Log(title = "计划通知", businessType = BusinessType.INSERT)
 @PostMapping
 public AjaxResult add(@RequestBody NoticePlan noticePlan)
 {
  return toAjax(noticePlanService.insertNoticePlan(noticePlan));
 }

 /**
  * 修改计划通知
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:edit')")
 @Log(title = "计划通知", businessType = BusinessType.UPDATE)
 @PutMapping
 public AjaxResult edit(@RequestBody NoticePlan noticePlan)
 {
  return toAjax(noticePlanService.updateNoticePlan(noticePlan));
 }

 /**
  * 删除计划通知
  */
 @PreAuthorize("@ss.hasPermi('plan:notice:remove')")
 @Log(title = "计划通知", businessType = BusinessType.DELETE)
 @DeleteMapping("/{ids}")
 public AjaxResult remove(@PathVariable Long[] ids)
 {
  return toAjax(noticePlanService.deleteNoticePlanByIds(ids));
 }
}
